/**
 * 页面预设值，本文件不要引入模块
 */

export default {
  // 页面需要用到的权限定义
  limits: {  // 用户权限
    // 路由权限
    $page: {
      label: '查看列表',
    },
    editItem: {
      label: '编辑角色',
    },
  },
  // 页面需要用到的 api定义
  apis: {
    list: {
      url: 'GET account_manage/role/',
      limits: '$page',
    },
    addRole: {
      url: 'POST account_manage/role/',
      limits: 'editItem',
    },
    editItem: {
      url: 'PUT account_manage/role/$id/',
      limits: 'editItem',
    },
    delRole: {
      url: 'DELETE account_manage/role/$id/',
      limits: 'editItem',
    },
    getLimit: {
      url: 'GET account_manage/role/$id/',
      limits: 'editItem',
    },
    editLimit: {
      url: 'PATCH account_manage/role/$id/',
      limits: 'editItem',
      onPreRequest: (source) => {
        console.log('source.data', source)
        const { id, authApi: api = '', authLimit: limit = '' } = source.rawData
        source.data = { id, api, limit }
        return source
      },
    },
    listMember: {
      url: 'GET account_manage/user',
      limits: 'editItem',
      mock: true,
    },
    editMember: {
      url: 'POST account_manage/user/assign_role/',
      limits: 'editItem',
      mock: true,
      onPreRequest: (source) => {
        const { ids, newRoleId } = source.data
        source.data = {
          user_list: ids.split(',').map((i) => Number(i)),
          role_list: newRoleId.split(',').map((i) => Number(i)),
        }
        return source
      },
    },
  },
}
